import {
  Injectable,
  MiddlewareConsumer,
  Module,
  NestMiddleware,
  NestModule,
  RequestMethod,
} from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { ServeStaticModule } from '@nestjs/serve-static';
import { join, resolve } from 'path';
import { NextFunction } from 'express';
import { GraphQLModule } from '@nestjs/graphql';
import { ProxyMiddleware } from './app.middleware';

const a = join(__dirname, '..', 'dist copy');
@Module({
  imports: [
    ServeStaticModule.forRoot({
      rootPath: a,
      // exclude: ['/api/(.*)'],
      // serveRoot: '/static', // 服务端路由前缀
      // serveStaticOptions:{index:false},
    }),
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule implements NestModule {
  configure(consumer: MiddlewareConsumer) {
    consumer.apply(ProxyMiddleware).forRoutes('*');
  }
}
